/* Copyright (C) 
 * 
 * Disclaim
 * This program is the property of AI Speech Ltd. It shall be communicated to
 * authorized personnel only. It is not to be disclosed outside the group without
 * prior written consent. If you are not sure if you’re authorized to read this
 * program, please contact info@aispeech.com before reading.
 * 
 */

#include "wtk/utils/wtk_utils_get_distance.h"

// 求弧度
double wtk_utils_radian(double d)
{
    return d * PI / 180.0;   //角度1? = π / 180
}

//计算距离
double wtk_utils_get_distance(double lat1, double lng1, double lat2, double lng2)
{
    double radLat1 = wtk_utils_radian(lat1);
    double radLat2 = wtk_utils_radian(lat2);
    double a = radLat1 - radLat2;
    double b = wtk_utils_radian(lng1) - wtk_utils_radian(lng2);

    double dst = 2 * asin((sqrt(pow(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2) )));

    dst = dst * EARTH_RADIUS;
    dst= round(dst * 10000) / 10000;
    return dst;
}

int wtk_utils_cmp_double(double d1, double d2){
    int result = 0;
    if ((d1-d2) > 0.000001 || fabs(d1-d2)<0.01){
	result = 1;
    } else{
	result = 0;
    }

    return result;
}